<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>

<body>
  <script>
    //Date.parse()和Date.UTC();
    let someDate = new Date(Date.parse("May 23 2022"));
    console.log(someDate);//Mon May 23 2022 00:00:00 GMT+0800 (中国标准时间)
    let someDate1 = new Date("Aug 11 2022"); //隐式调用Date.parse.
    console.log(someDate1);//Thu Aug 11 2022 00:00:00 GMT+0800 (中国标准时间)

    let yk2 = new Date(Date.UTC(2022, 7, 11, 17, 15, 27));
    console.log(yk2);//Fri Aug 12 2022 01:15:27 GMT+0800 (中国标准时间)
    let yk3 = new Date(2022, 7, 11, 17, 16, 45); //Date.UTC()也会被Date隐式调用.
    console.log(yk3); //Thu Aug 11 2022 17:16:45 GMT+0800 (中国标准时间)
    //Date.now()用于代码分析.
    const arr = [1, 2, 3, 4, 5, 6, 2, 1];
    let start = Date.now();
    for (let i = 0, len = arr.length; i < len; i++) {
      console.log(arr[i]);
    }
    let stop = Date.now();
    let time = stop - start;
    console.log(time);

    let date1 = new Date(2019, 0, 1);
    let date2 = new Date(2019, 1, 1);
    console.log(date1 < date2);//true

    console.log(date1.toDateString());//Tue Jan 01 2019
    console.log(date1.toTimeString());//00:00:00 GMT+0800 (中国标准时间)
    console.log(date1.toLocaleDateString());//2019/1/1
    console.log(date1.toLocaleTimeString());//00:00:00
    console.log(date1.toUTCString());//Mon, 31 Dec 2018 16:00:00 GMT
    //正则表达式
    let patten1 = /at/g //匹配字符串中的所有"at"
    let patten2 = /[bc]at/i; //匹配第一个bat或cat,忽略大小写.
    let patten3 = /.at/gi; //匹配所有的以"at"结尾的三字符组合,忽略大小写.
    let patten4 = /\[bc\]at/i; //匹配第一个 "[bc]at",忽略大小写.
    let patten5 = new RegExp("[bc]at", "i"); //构造函数创建RegExp.
    let patten6 = new RegExp(patten3, "i")
    // RegExp实例属性
    console.log(patten4.global);//false
    console.log(patten4.ignoreCase)//true
    console.log(patten4.source);//\[bc\]at
    console.log(patten4.flags);//i

    //exec()
    let text = "mom and dad and baby";
    let pattern = /mom( and dad( and baby)?)?/gi;
    let matches = pattern.exec(text);
    console.log(matches.index);//0
    console.log(matches.input);//mom and dad and baby
    console.log(matches[0]);//mom and dad and baby ,整个字符串
    console.log(matches[1]);//and dad and baby , 第一个捕获组
    console.log(matches[2]);//and baby , 第二个捕获组

    let text1 = "cat, bat, sat, fat";
    let pattern1 = /.at/g;  //如果不设置全局匹配,永远是0 cat 3 ,index和lastIndex不会改变.
    // 如果设置为粘附模式,每次调用exec()只会在lastIndex上寻找匹配项.向前设置lastIndex可以
    //pattern.lastIndex = 5 , 继续找到下一个匹配项.
    let matches1 = pattern1.exec(text1);
    console.log(matches1.index);//0
    console.log(matches1[0]);//cat
    console.log(pattern1.lastIndex);//3
    matches1 = pattern1.exec(text1);
    console.log(matches1.index);//5
    console.log(matches1[0]);//bat
    console.log(pattern1.lastIndex);//8
    //test()测试模式是否匹配,验证用户输入.
    let text2 = "000-00-0000";
    let pattern2 = /\d{3}-\d{2}-\d{4}/;
    if(pattern2.test(text2)){
      console.log("The pattern was matched");
    }
  </script>
</body>

</html>